package com.qdlc.p2p.dal.model;


import org.springframework.beans.BeanUtils;

import com.qdlc.p2p.common.exception.UserException;
import com.qdlc.p2p.common.util.Page;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.common.util.ValidateUtil;
import com.qdlc.p2p.dal.dto.CardSend;

/**
 * Created by lenovo on 2015/12/21.
 */
public class CardSendModel extends CardSend {

    /** 当前页码 */
    private int page;
    /** 每页总数 **/
    private int rows;

    /** 每页数据条数 */
    private int size = Page.ROWS;

    private String searchName;

    /**
     * 添加开始时间
     */
    private String receiveStartTime;
    /**
     * 添加结束时间
     */
    private String receiveEndTime;

    public String getSearchName() {
        return searchName;
    }

    public void setSearchName(String searchName) {
        this.searchName = searchName;
    }

    public String getReceiveStartTime() {
        return receiveStartTime;
    }

    public void setReceiveStartTime(String receiveStartTime) {
        this.receiveStartTime = receiveStartTime;
    }

    public String getReceiveEndTime() {
        return receiveEndTime;
    }

    public void setReceiveEndTime(String receiveEndTime) {
        this.receiveEndTime = receiveEndTime;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public static CardSendModel instance(CardSend cardSend) {
        CardSendModel cardSendModel = new CardSendModel();
        BeanUtils.copyProperties(cardSend, cardSendModel);
        return cardSendModel;
    }
    
    /**
	 * 绑定邮箱校验
	 */
	public void valid() {
		if (StringUtil.isEmpty(getSendName())) {
			throw new UserException("发送人姓名为空", 1);
		}
		if (StringUtil.isEmpty(getSendPhone())) {
			throw new UserException("发件人手机为空", 1);
		}
		if (StringUtil.isEmpty(getReceiveName())) {
			throw new UserException("收件人姓名为空", 1);
		}
		if (StringUtil.isEmpty(getReceiveAddress())) {
			throw new UserException("收件人地址为空", 1);
		}
		if (StringUtil.isEmpty(getReceivePhone())) {
			throw new UserException("收件人手机为空", 1);
		}
		if (!ValidateUtil.isChinese(getSendName())) {
			throw new UserException("发送人姓名格式错误！", 1);
		}
		if (!ValidateUtil.isChinese(getReceiveName())) {
			throw new UserException("收件人姓名格式错误！", 1);
		}
		if (!ValidateUtil.isPhone(getSendPhone())) {
			throw new UserException("发送人号码格式错误！", 1);
		}
		if (!ValidateUtil.isPhone(getReceivePhone())) {
			throw new UserException("收件人号码格式错误！", 1);
		}
		if (StringUtil.isNotEmpty(getRemark())&&getRemark().length()>255) {
			throw new UserException("祝福语长度过长", 1);
		}
		if(getReceiveAddress().length()>255){
			throw new UserException("收件人地址过长", 1);
		}
	}
}
